package com.gem.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gem.pojo.Users;
import com.gem.service.BooksService;
import com.gem.service.UsersService;

/**
 * Servlet implementation class GetUsersByPage
 */
@WebServlet("/GetUsersByPage")
public class GetUsersByPage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetUsersByPage() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		UsersService ub=new UsersService();
		
		int page_user_num=3;
		int page_num=0;
		int user_num=0;
		int now_page_num=1;
		if(request.getAttribute("id")!=null){
			now_page_num=Integer.parseInt(request.getParameter("id"));
			System.out.println(now_page_num);
		}
		user_num=ub.getUsersAcount();
		HttpSession session=request.getSession();
		page_num=user_num/page_user_num+1;
		
		List list=ub.getAllUsersByPage(page_user_num, now_page_num);
		session.setAttribute("page_num", page_num);
		session.setAttribute("listuser", list);
		response.sendRedirect("userpage.jsp");
				
	}

}
